/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bs;

import java.io.InputStream;
import java.sql.Connection;
import java.util.HashMap;
import javax.swing.JPanel;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.swing.JRViewer;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author Bone
 */
public class GestorRelatorios {

   

    public InputStream getInputStream(String nome) {
        String arquivo = "relatorios/" + nome +".jasper";
        return getClass().getResourceAsStream(arquivo);
    }

    /**
     * Método que cria e torna visível a tela que exibe o relatório.
     * @param nome
     * @param par
     * @throws Exception
     */
    public void exibirRelatorio(String nome, HashMap par) throws Exception {
        JasperPrint jp = JasperFillManager.fillReport(getInputStream(nome), par);
        JasperViewer.viewReport(jp, false);
    }

    public void exibirRelatorio(String nome, HashMap par, Connection cnn) throws Exception {
        JasperPrint jp = JasperFillManager.fillReport(getInputStream(nome), par, cnn);
        jp.setName("Relatorio");
        JasperViewer.viewReport(jp, false);
    }

    public void exibirRelatorio(String nome, HashMap par, Connection cnn, JPanel tela) throws Exception {
        JasperPrint jp = JasperFillManager.fillReport(getInputStream(nome), par, cnn);
        JRViewer jRViewer = new JRViewer(jp);
        jRViewer.setName("Relatório");
        tela.removeAll();
        tela.add("relatorio", jRViewer);
        tela.validate();
        tela.repaint();
    }


//    public void exibirRelatorio(String nome, HashMap par, JRDataSource dataSource) throws Exception {
//        JasperPrint jp = JasperFillManager.fillReport(getInputStream(nome), par, dataSource);
//        JasperViewer.viewReport(jp, false);
//    }
}
